module EmployeePositionRepositiory

  def check_certificate employee, result=[]
    certificates = Employee.employee_certificates(employee["id"])
    employee["positions"].each do |employee_position|
      position_certificate_standard = PositionCertificateStandard.find_certificate_standard employee_position["id"], employee_position["organ_id"]
      unless (lost_certificates = position_certificate_standard.map(&:id) - certificates.map(&:certificate_id)).empty?
        result.push({employee: employee, position: employee_position["id"], organization: employee_position["organ_id"], certificates: position_certificate_standard.select{|e| lost_certificates.include? e.id}.uniq})
      end
    end
    result
  end

  def find_organs_by_employee_and_position employee, position
    Employee::Position.where(employee: employee, position: position)
  end

  def find_positions_by_employee_and_organ employee, organization
    Employee::Position.where(employee: employee, organization: organization)
  end

end
